// Source File Name:   CPFloat.java

package com.vhly.classfile;

import java.io.*;

// Referenced classes of package com.vhly.classfile:
//            CPEntry

public class CPFloat
        extends CPEntry {

    private float value;
    private static byte buf[] = new byte[4];
    public static final int tag = 4;

    public CPFloat() {
        value = 0.0F;
    }

    public CPFloat(float f) {
        value = f;
    }

    public float getFloat() {
        return value;
    }

    public void setFloat(float f) {
        value = f;
    }

    public void write(DataOutputStream dataoutputstream)
            throws IOException {
        dataoutputstream.write(4);
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(4);
        DataOutputStream dataoutputstream1 = new DataOutputStream(bytearrayoutputstream);
        dataoutputstream1.writeFloat(value);
        buf = bytearrayoutputstream.toByteArray();
        dataoutputstream1.close();
        bytearrayoutputstream.close();
        dataoutputstream.write(buf, 0, 4);
    }

    public void read(DataInputStream datainputstream)
            throws IOException {
        datainputstream.read(buf, 0, 4);
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(buf);
        DataInputStream datainputstream1 = new DataInputStream(bytearrayinputstream);
        value = datainputstream1.readFloat();
        datainputstream1.close();
        bytearrayinputstream.close();
    }

    public int getType() {
        return 4;
    }

    /**
     * 比较指定元素是否和自身相等
     *
     * @param e CPEntry
     * @return 0 equals -1 no
     */
    public boolean equalsTo(CPEntry e) {
        CPFloat cpd = (CPFloat) e;
        return this.value == cpd.value;
    }

}